1765K - Torus Path - CodeForces Solution


dp greedy math *1500

Please click on ads to support us..

Python Code:

l=[*map(int,open(0).read().split())]
n=l[0];o=l[1:];print(sum(o)-min(o[n-1:-1:n-1]))

C++ Code:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
const int INF = numeric_limits<int>::max();
const int nax = (int)(590001);
const int mod = 1e9 + 7;

template<class X, class Y>
bool maximize(X& x, const Y y) {
    if (y > x) {x = y; return true;}
    return false;
}
template<class X, class Y>
bool minimize(X& x, const Y y) {
    if (y < x) {x = y; return true;}
    return false;
}

int nxt() {
    int x; cin >> x;
    return x;
}

#define Fi first
#define Se second
#define pii pair<int, int> 
#define vi vector<int>
#define vvi vector<vi>

void solve() {
    int n; cin >> n;

    vvi grid(n, vi(n));

    int sum = 0;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> grid[i][j];
            sum += grid[i][j];
        } 
    }

    int mini = INT_MAX;

    // for(int i = 0; i < n - 1; i++) {
    //     mini = min(mini, grid[i][i + 1]);
    // }

    for(int i = 0; i < n; i++) {
        mini = min(mini, grid[i][n - i - 1]);
    }

    cout << (sum - mini) << '\n';
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    // code here
    solve();

    return 0;
}


Comments

Submit
0 Comments
More Questions

1538B - Friends and Candies
580A - Kefa and First Steps
1038B - Non-Coprime Partition
43A - Football
50A - Domino piling
479A - Expression
1480A - Yet Another String Game
1216C - White Sheet
1648A - Weird Sum
427A - Police Recruits
535A - Tavas and Nafas
581A - Vasya the Hipster
1537B - Bad Boy
1406B - Maximum Product
507B - Amr and Pins
379A - New Year Candles
1154A - Restoring Three Numbers
750A - New Year and Hurry
705A - Hulk
492B - Vanya and Lanterns
1374C - Move Brackets
1476A - K-divisible Sum
1333A - Little Artem
432D - Prefixes and Suffixes
486A - Calculating Function
1373B - 01 Game
1187A - Stickers and Toys
313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends